<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>采用事件委托</title>
</head>
<body>
    <ul id="ul">
        <li>1</li>
        <li>2</li>
        <li>3</li>
        <li>4</li>
        <li>5</li>
    </ul>

    <script>
        var list = document.querySelectorAll('li')
        function showText (el) {
            let obj = el.target
            if(obj.nodeName.toLowerCase() === 'li'){
                console.log(obj.innerHTML)
            }
        }
        
        // 对于元素数量过大的时候
        // 对每个元素绑定事件，会增加内存损耗
        // for(let item of list){
        //     item.onclick = showText
        // }

        // var ul = document.getElementById('ul')
        // ul.addEventListener('click', showText)
    </script>
    
</body>
</html>